import { Reducer, Effect } from 'umi';
import { exportUsers } from '@/services/derive';
import {message } from 'antd';
export interface StateType {
    status?: 'ok' | 'error';
    type?: string;
    currentAuthority?: 'user' | 'guest' | 'admin';
  }
export interface LoginModelType {
  namespace: string;
  state: StateType;
  effects: {
    deriveUser: Effect;
  };
  reducers: {
    changeLoginStatus: Reducer<StateType>;
  };
}

const Model: LoginModelType = {
  namespace: 'derive',
  state:{},
  effects: {
    *deriveUser({ payload,callback }, { call, put }) {
       const  derive= yield call(exportUsers)
       console.log(derive)
       if (derive instanceof Blob) {
        if (callback && typeof callback === 'function') {
          console.log(callback)
          callback(derive);
        }
      } else {
        message.warning('下载出现错误', 5);
      }
    //     yield put({
    //  type: 'changeLoginStatus',
    // });
    },
  },

  reducers: {
    changeLoginStatus(state, { payload }) {
      return {
        ...state,
        status: payload.status,
      };
    },
  },
};

export default Model;
